﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 影楼婚纱摄影系统
{
    public partial class 员工个人业绩查询 : Form
    {
        // 获取员工ID值
        MainForm myForm = new MainForm();
        string form2 = MainForm.Id;
        string form3 = MainForm.Name1;

        public 员工个人业绩查询()
        {
            InitializeComponent();
        }

        private void 员工个人业绩查询_Load(object sender, EventArgs e)
        {
            //label标签的文本改为员工姓名
            label1.Text = form3+"员工";
        }

        private void button1_Click(object sender, EventArgs e)
        {


            if (textBox1.Text != "")
            {
                //数据库连接串
                string str = System.Configuration.ConfigurationManager.ConnectionStrings["marry"].ConnectionString;
                //创建SqlConnection的实例
                SqlConnection conn = null;
                try
                {
                    conn = new SqlConnection(str);
                    //打开数据库
                    conn.Open();
                    string sql = "Select Year(o.ordertime) as 年份,Month(o.ordertime) as 月份,SUM(price*s.[percentage]) as 个人提成,s.basesalary as 基础工资,SUM(price*s.[percentage])+s.basesalary as 总工资 from [order] as o ,staff as s where o.staffId like '%{0}%' and s.sId='{0}' and Year(o.ordertime)='{1}' Group by Year(ordertime),Month(ordertime),s.basesalary";
                    //填充占位符
                    sql = string.Format(sql, form2, textBox1.Text);
                    //创建SqlDataAdapter类的对象
                    SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
                    //创建DataSet类的对象
                    DataSet ds = new DataSet();
                    //使用SqlDataAdapter对象sda将查新结果填充到DataSet对象ds中
                    sda.Fill(ds);
                    //设置表格控件的DataSource属性
                    dataGridView1.DataSource = ds.Tables[0];
                }
                catch (Exception ex)
                {
                    MessageBox.Show("出现错误！" + ex.Message);
                }
                finally
                {
                    if (conn != null)
                    {
                        //关闭数据库连接
                        conn.Close();
                    }
                }
            }

            else
            {
                MessageBox.Show("请输入年份");
            }
        }


    }
}
